package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.logic.contract.SystemSettingsContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.SystemSettingsPersnter;
import com.hzdesk.media.koreabatchmatvector.utils.SharedPreferencesUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/9.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 * <p>
 * todo                                                                  系统设置
 */

public class SystemSettingsActivity extends BaseActivity implements SystemSettingsContract.ISystemSettingsView {


    @BindView(R.id.activity_system_setting_iv_back)
    ImageView activitySystemSettingIvBack;
    @BindView(R.id.activity_system_setting_et_name)
    TextView activitySystemSettingEtName;
    @BindView(R.id.fragment_my_set_ll_mouse_set)
    LinearLayout fragmentMySetLlMouseSet;
    @BindView(R.id.activity_system_setting_ll_config_file)
    LinearLayout activitySystemSettingLlConfigFile;
    @BindView(R.id.activity_system_setting_ll_logo_image)
    LinearLayout activitySystemSettingLlLogoImage;
    @BindView(R.id.activity_system_setting_ll_block_length)
    LinearLayout activitySystemSettingLlBlockLength;
    @BindView(R.id.activity_system_setting_tv_screen_path)
    TextView activitySystemSettingTvScreenPath;
    @BindView(R.id.activity_system_setting_ll_screen_path)
    LinearLayout activitySystemSettingLlScreenPath;
    @BindView(R.id.activity_system_setting_tv_video_path)
    TextView activitySystemSettingTvVideoPath;
    @BindView(R.id.activity_system_setting_ll_video_path)
    LinearLayout activitySystemSettingLlVideoPath;
    @BindView(R.id.activity_system_setting_tv_binding_cloud_service)
    TextView activitySystemSettingTvBindingCloudService;
    @BindView(R.id.activity_system_setting_ll_binding_cloud_service)
    LinearLayout activitySystemSettingLlBindingCloudService;
    @BindView(R.id.activity_system_setting_tv_about_device)
    TextView activitySystemSettingTvAboutDevice;
    @BindView(R.id.activity_system_setting_ll_about_device)
    LinearLayout activitySystemSettingLlAboutDevice;
    @BindView(R.id.activity_system_setting_rl_bg)
    RelativeLayout activitySystemSettingRlBg;
    @BindView(R.id.activity_system_setting_lin_meeting_name)
    LinearLayout activitySystemSettingLinMeetingName;
    @BindView(R.id.activity_system_setting_ll_record_mode)
    LinearLayout activitySystemSettingLlRecordMode;
    @BindView(R.id.activity_system_setting_ll_user_mode)
    LinearLayout activitySystemSettingLlUserMode;
    @BindView(R.id.activity_system_setting_ll_protocal)
    LinearLayout activitySystemSettingLlProtocal;
    @BindView(R.id.activity_system_setting_tv_block_length)
    TextView activitySystemSettingTvBlockLength;
    @BindView(R.id.activity_system_setting_tv_record_mode)
    TextView activitySystemSettingTvRecordMode;
    @BindView(R.id.activity_system_setting_tv_user_mode)
    TextView activitySystemSettingTvUserMode;
    @BindView(R.id.activity_system_setting_tv_protocal)
    TextView activitySystemSettingTvProtocal;
    @BindView(R.id.activity_system_setting_ll_net_work)
    LinearLayout activitySystemSettingLlNetWork;


    private SystemSettingsPersnter mSystemSettingsPersnter = new SystemSettingsPersnter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_setting);
        ButterKnife.bind(this);
        mSystemSettingsPersnter.initDate(this);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLinMeetingName);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(fragmentMySetLlMouseSet);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlConfigFile);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlLogoImage);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlBlockLength);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlRecordMode);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlScreenPath);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlVideoPath);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlUserMode);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlProtocal);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlBindingCloudService);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlAboutDevice);
        mSystemSettingsPersnter.setOnHoverListenerAndOnFocusChangeListener(activitySystemSettingLlNetWork);
    }

    @OnClick({R.id.activity_system_setting_iv_back, R.id.fragment_my_set_ll_mouse_set, R.id.activity_system_setting_ll_config_file,
            R.id.activity_system_setting_ll_logo_image, R.id.activity_system_setting_ll_block_length, R.id.activity_system_setting_ll_screen_path,
            R.id.activity_system_setting_ll_video_path, R.id.activity_system_setting_ll_binding_cloud_service, R.id.activity_system_setting_ll_about_device,
            R.id.activity_system_setting_lin_meeting_name, R.id.activity_system_setting_ll_record_mode, R.id.activity_system_setting_ll_user_mode,
            R.id.activity_system_setting_ll_protocal,R.id.activity_system_setting_ll_net_work})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_system_setting_iv_back:                                              //返回
                mSystemSettingsPersnter.onCliackedBack();
                break;
            case R.id.activity_system_setting_lin_meeting_name:
                mSystemSettingsPersnter.onclickedMeetingName();
                break;
            case R.id.fragment_my_set_ll_mouse_set:                                                 //批注功能
                mSystemSettingsPersnter.onClickedNotation();
                break;
            case R.id.activity_system_setting_ll_config_file:                                       //管理配置文件
                mSystemSettingsPersnter.ConfigFileManger(this);
                break;
            case R.id.activity_system_setting_ll_net_work:                                          // 网络设置
                mSystemSettingsPersnter.onClickedNetWork();
                break;
            case R.id.activity_system_setting_ll_logo_image:                                        //设置LOGO图片
                mSystemSettingsPersnter.onClickedSetLoge();
                break;
            case R.id.activity_system_setting_ll_block_length:                                      //分段时长
                mSystemSettingsPersnter.onclickedBlockLength();
                break;
            case R.id.activity_system_setting_ll_screen_path:                                       //截图文件路径
                mSystemSettingsPersnter.onclickedScreenshotsPath();
                break;
            case R.id.activity_system_setting_ll_video_path:                                        //视频文件路径
                mSystemSettingsPersnter.onclickedVidoPath();
                break;
            case R.id.activity_system_setting_ll_binding_cloud_service:                             //绑定云服务
                mSystemSettingsPersnter.onclickedBindCulde();
                break;
            case R.id.activity_system_setting_ll_about_device:                                      //关于可立批
                mSystemSettingsPersnter.onclickedAbout();
                break;
            case R.id.activity_system_setting_ll_record_mode:                                       //录制模式
                mSystemSettingsPersnter.onclickedRecordingMode();
                break;
            case R.id.activity_system_setting_ll_user_mode:                                         //使用模式
                mSystemSettingsPersnter.onclickedModel();
                break;
            case R.id.activity_system_setting_ll_protocal:                                          //协议
                mSystemSettingsPersnter.onClickChangeProtocal();
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activitySystemSettingRlBg.setBackgroundResource(updateBg[selector]);
    }

    @Override
    public void focusChange(View v) {
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
        }
    }

    @Override
    public void initDate() {

    }

    @Override
    public void meetName(String msg) {

    }

    @Override
    public String getMeetName() {
        return null;
    }

    @Override
    public void toChangeMeetingNamePager() {

    }

    @Override
    public void todNotationPager() {
        toOtherPager(MouseListActivity.class);
    }

    @Override
    public void toSetLogePager() {
        toOtherPager(ShowLogeActivity.class);
    }

    @Override
    public void toBlockLengthPager() {
        // Log.e("lk", "--------------------------");
        Intent intent = new Intent();
        intent.setClass(SystemSettingsActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_SUBSETION_TIME);
        startActivity(intent);


    }

    @Override
    public void toRecordingModePager() {
        Intent intent = new Intent();
        intent.setClass(SystemSettingsActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_RECORD_MODE);
        startActivity(intent);

    }

    @Override
    public void toScreenshotsPathPager() {

    }

    @Override
    public void toVidoPathpAGER() {
        toOtherPager(FileSelectActivity.class);
    }

    @Override
    public void toModelPager() {
        Intent intent = new Intent();
        intent.setClass(SystemSettingsActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_USER_MODE);
        startActivity(intent);

    }

    @Override
    public void toBindCuldePager() {
        toOtherPager(BoundCloudServiceActivity.class);
    }

    @Override
    public void toAboutPager() {
        toOtherPager(AboutActivity.class);
    }

    @Override
    public void toFinshPager() {
        finish();
    }

    @Override
    public void toProtocalPager() {
        Intent intent = new Intent();
        intent.setClass(SystemSettingsActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_PROTOCOL);
        startActivity(intent);

    }

    @Override
    public void toMeetingNamePage() {
        toOtherPager(MeetingNameActivity.class);

    }

    @Override
    public void toNetWorkPager() {
        toOtherPager(SettingNetWorkActivity.class);
    }
    // 页面跳转
    private void toOtherPager(Class<?> cls) {
        startActivity(new Intent(SystemSettingsActivity.this, cls));
    }

    @Override
    protected void onResume() {
        super.onResume();
        activitySystemSettingEtName.setText(SharedPreferencesUtils.getMeetingName(this));
        long time = SharedPreferencesUtils.getSubSectionTime(this);
        String timeString = (time / 60 / 1000) + "分钟";
        activitySystemSettingTvBlockLength.setText(timeString);
        activitySystemSettingTvScreenPath.setText(SharedPreferencesUtils.getScreenSavePath(this));
        activitySystemSettingTvVideoPath.setText(SharedPreferencesUtils.getVideoSavePath(this));
        if (SharedPreferencesUtils.getRecordMode(this) == 1) {
            activitySystemSettingTvRecordMode.setText("信号源+麦克风");
        } else {
            activitySystemSettingTvRecordMode.setText("信号源");
        }
        if (SharedPreferencesUtils.getUserMode(this) == 1) {
            activitySystemSettingTvUserMode.setText("普通模式");
        } else {
            activitySystemSettingTvUserMode.setText("特权模式");
        }
        if (SharedPreferencesUtils.getProtocal(this) == 1) {
            activitySystemSettingTvProtocal.setText("HDMI IN");
        } else {
            activitySystemSettingTvProtocal.setText("Miracast");
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
